//
//  UIBarButtonItem + Extension.swift
//  微博
//
//  Created by 刘保满 on 16/5/20.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

extension UIBarButtonItem  {
    
    //便利的构造函数
    convenience init(imageName: String? = nil,title:String? = nil,target: AnyObject?, action: Selector ) {
        
        self.init()
        
        let btn = UIButton()
        
        if let img = imageName {
            
            btn.setImage(UIImage(named: img ), forState: .Normal)
            btn.setImage(UIImage(named: img + "_highlighted"), forState: .Highlighted)
        }
        
        
        btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: -8, bottom: 0, right: 0)
        btn.setTitle(title, forState: .Normal)
    
        
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        

        btn.sizeToFit()
        
       self.customView = btn
        
    }
    
    
}



